/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 07 - 06
 * Time: 22:16
 */

/**
 * Forward declaration of guess API.
 * @param  num   your guess
 * @return 	     -1 if num is higher than the picked number
 *			      1 if num is lower than the picked number
 *               otherwise return 0
 * int guess(int num);
 */
public class Solution extends GuessGame {
    public int guessNumber(int n) {
        int left = 1;
        int right = n;
        while(left <= right) {
            int mid = left + (right - left) / 2;//mid相当于我要猜的数
            if(guess(mid) == -1) {              //1~n之间的数相当于系统自己出好
                right = mid - 1;
            }else if(guess(mid) == 1) {
                left = mid + 1;
            }else {
                return mid;
            }
        }
        return 0;//这一行是没用的，永远不会返回0，只会在上面返回mid
    }
}
